package com.qf.cm.dao;

import com.qf.cm.pojo.Subitem;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description: 公用常量
 * @Data: 2022/9/7 17:33
 * @Pacakge: com.qf.cm.dao
 * @ClassName: SubitemDao
 * @Author: fan
 */
@Repository
public interface SubitemDao {
    @Select("select * from subitem where pid = #{pid}")
    List<Subitem> findSubitemByPid(@Param("pid")Integer pid);
    @Results(id = "findSubitemBySname",value = {
            @Result(column = "suid" ,property ="suid" ),
            @Result(column ="sname" ,property = "sname" ),
            @Result(column ="starttime",property ="starttime"),
            @Result(column ="endtime" ,property ="endtime" ),
            @Result(column ="pid" ,property ="pid" ),
            @Result(column = "updatetime",property ="updatetime" ),
            @Result(column = "status",property ="status" ),
            @Result(column = "suid",property ="items",
                many = @Many(select = "com.qf.cm.dao.ItemsDao.findItemBySuid",fetchType = FetchType.EAGER)
            )
    })
    @Select("select * from subitem where sname = #{sname}")
    Subitem findSubitemBySname(@Param("sname") String sname);

    @ResultMap("findSubitemBySname")
    @Select("select * from subitem where suid = #{suid}" )
    Subitem findSubitemBySid(@Param("suid") String suid);
}
